<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" id='image' name="image" class="fileInput">
<div class="btn"
     style="width: 50px;height: 25px;border: 1px solid lightgray;background: gray;margin-top: 5px;text-align: center">提交
</div>
</body>
<script src="_HTTPJS_/jquery-3.2.1.min.js"></script>
<script src="_HTTPJS_/common.js"></script>
<script>

    console.log('thisDirFiles[0]=={$thisDirFiles[0]}')
    console.log('count=={$fileCount}')
    console.log('fileNameStr=={$fileNameStr}')
    var len = '{$fileCount}';
    // for (var i = 0; i < len; i++) {
    //     console.log(i)
    //     console.log('thisDirFiles[' + i + ']=={/////thisDirFiles[i]}')
    // }
    $(".btn").click(function () {

        var fileNameStr = '{$fileNameStr}';
        var formdata = new FormData();
        imgFile = document.getElementById('image').files[0];

        formdata.append("image", imgFile);
        formdata.append("dir", '{$dir}');
        formdata.append("fileName", imgFile.name);
        console.log('imgFile', imgFile);
        console.log('imgFile.name', imgFile.name);

        if (fileNameStr.indexOf(imgFile.name) != -1) {
            alert('同名文件已存在，请改名')
            return
        }

        $.ajax({
            type: "post",
            url: 'http://api.meal.52g3.cc/upload/File/img',
            processData: false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
            contentType: false, // 不设置Content-type请求头
            data: formdata,
            error: function (res) {

                console.log("上传失败", res);
            },
            success: function (res) {

                console.log("上传成功", res);
                var url = window.location.href;
                console.log("url", url, location.href);
                window.location.href = url

            }
        })
    });

</script>
</html>